
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.core.molecular_orbitals &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.core.molecular_orbitals</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.core.molecular_orbitals</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module implements a MolecularOrbital class to represent band character in</span>
<span class="sd">solids. Usefull for predicting PDOS character from structural information.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">chain</span><span class="p">,</span> <span class="n">combinations</span>

<span class="kn">from</span> <span class="nn">pymatgen.core.periodic_table</span> <span class="kn">import</span> <span class="n">Element</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.composition</span> <span class="kn">import</span> <span class="n">Composition</span>


<div class="viewcode-block" id="MolecularOrbitals"><a class="viewcode-back" href="../../../pymatgen.core.molecular_orbitals.html#pymatgen.core.molecular_orbitals.MolecularOrbitals">[docs]</a><span class="k">class</span> <span class="nc">MolecularOrbitals</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Represents the character of bands in a solid. The input is a chemical</span>
<span class="sd">    formula, since no structural characteristics are taken into account.</span>

<span class="sd">    The band character of a crystal emerges from the atomic orbitals of the</span>
<span class="sd">    constituant ions, hybridization/covalent bonds, and the spin-orbit</span>
<span class="sd">    interaction (ex: Fe2O3). Right now the orbitals are only built from</span>
<span class="sd">    the uncharged atomic species. Functionality can be improved by:</span>
<span class="sd">    1) calculate charged ion orbital energies</span>
<span class="sd">    2) incorportate the coordination enviornment to account for covalant bonds</span>

<span class="sd">    The atomic orbital energies are stored in pymatgen.core.periodic_table.JSON</span>

<span class="sd">    &gt;&gt;&gt; MOs = MolecularOrbitals(&#39;SrTiO3&#39;)</span>
<span class="sd">    &gt;&gt;&gt; MOs.band_edges</span>
<span class="sd">    {&#39;HOMO&#39;:[&#39;O&#39;,&#39;2p&#39;,-0.338381], &#39;LUMO&#39;:[&#39;Ti&#39;,&#39;3d&#39;,-0.17001], &#39;metal&#39;:False}</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">formula</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            chemical formula as a string. formula must have integer subscripts</span>
<span class="sd">            Ex: &#39;SrTiO3&#39;</span>

<span class="sd">        Attributes:</span>
<span class="sd">            composition: the composition as a dictionary.</span>
<span class="sd">                         Ex: {&#39;Sr&#39;: 1, &#39;Ti&#39;: 1, &#39;O&#39;, 3}</span>
<span class="sd">            elements:    the dictionary keys for the composition</span>
<span class="sd">            elec_neg:    the maximum pairwise electronegetivity difference</span>
<span class="sd">            aos:         the consituant atomic orbitals for each element as a</span>
<span class="sd">                         dictionary</span>
<span class="sd">            band_edges:  dictionary containing the highest occupied molecular</span>
<span class="sd">                         orbital (HOMO), lowest unocupied molecular orbital</span>
<span class="sd">                         (LUMO), and whether the material is predicted to be a</span>
<span class="sd">                         metal</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">composition</span> <span class="o">=</span> <span class="n">Composition</span><span class="p">(</span><span class="n">formula</span><span class="p">)</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">elements</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">subscript</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">float</span><span class="p">(</span><span class="n">subscript</span><span class="p">)</span><span class="o">.</span><span class="n">is_integer</span><span class="p">():</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;composition subscripts must be integers&#39;</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">elec_neg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_electronegativity</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">aos</span> <span class="o">=</span> <span class="p">{</span><span class="nb">str</span><span class="p">(</span><span class="n">el</span><span class="p">):</span> <span class="p">[[</span><span class="nb">str</span><span class="p">(</span><span class="n">el</span><span class="p">),</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">]</span>
                              <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">Element</span><span class="p">(</span><span class="n">el</span><span class="p">)</span><span class="o">.</span><span class="n">atomic_orbitals</span><span class="o">.</span><span class="n">items</span><span class="p">()]</span>
                    <span class="k">for</span> <span class="n">el</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">elements</span><span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">band_edges</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">obtain_band_edges</span><span class="p">()</span>

<div class="viewcode-block" id="MolecularOrbitals.max_electronegativity"><a class="viewcode-back" href="../../../pymatgen.core.molecular_orbitals.html#pymatgen.core.molecular_orbitals.MolecularOrbitals.max_electronegativity">[docs]</a>    <span class="k">def</span> <span class="nf">max_electronegativity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns:</span>
<span class="sd">            The maximum pairwise electronegativity difference.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">maximum</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">e1</span><span class="p">,</span> <span class="n">e2</span> <span class="ow">in</span> <span class="n">combinations</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">elements</span><span class="p">,</span> <span class="mi">2</span><span class="p">):</span>
            <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">Element</span><span class="p">(</span><span class="n">e1</span><span class="p">)</span><span class="o">.</span><span class="n">X</span> <span class="o">-</span> <span class="n">Element</span><span class="p">(</span><span class="n">e2</span><span class="p">)</span><span class="o">.</span><span class="n">X</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">maximum</span><span class="p">:</span>
                <span class="n">maximum</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="n">Element</span><span class="p">(</span><span class="n">e1</span><span class="p">)</span><span class="o">.</span><span class="n">X</span> <span class="o">-</span> <span class="n">Element</span><span class="p">(</span><span class="n">e2</span><span class="p">)</span><span class="o">.</span><span class="n">X</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">maximum</span></div>

<div class="viewcode-block" id="MolecularOrbitals.aos_as_list"><a class="viewcode-back" href="../../../pymatgen.core.molecular_orbitals.html#pymatgen.core.molecular_orbitals.MolecularOrbitals.aos_as_list">[docs]</a>    <span class="k">def</span> <span class="nf">aos_as_list</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns:</span>
<span class="sd">            A list of atomic orbitals, sorted from lowest to highest energy.</span>

<span class="sd">            The orbitals energies in eV are represented as</span>
<span class="sd">                [[&#39;O&#39;, &#39;1s&#39;, -18.758245], [&#39;O&#39;, &#39;2s&#39;, -0.871362], [&#39;O&#39;, &#39;2p&#39;, -0.338381]]</span>
<span class="sd">            Data is obtained from</span>
<span class="sd">            https://www.nist.gov/pml/data/atomic-reference-data-electronic-structure-calculations</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">chain</span><span class="o">.</span><span class="n">from_iterable</span><span class="p">(</span>
            <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">aos</span><span class="p">[</span><span class="n">el</span><span class="p">]</span> <span class="o">*</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">composition</span><span class="p">[</span><span class="n">el</span><span class="p">])</span> <span class="k">for</span> <span class="n">el</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">elements</span><span class="p">]</span>
        <span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span></div>

<div class="viewcode-block" id="MolecularOrbitals.obtain_band_edges"><a class="viewcode-back" href="../../../pymatgen.core.molecular_orbitals.html#pymatgen.core.molecular_orbitals.MolecularOrbitals.obtain_band_edges">[docs]</a>    <span class="k">def</span> <span class="nf">obtain_band_edges</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Fill up the atomic orbitals with available electrons.</span>
<span class="sd">        Returns:</span>
<span class="sd">            HOMO, LUMO, and whether it&#39;s a metal.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">orbitals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">aos_as_list</span><span class="p">()</span>
        <span class="n">electrons</span> <span class="o">=</span> <span class="n">Composition</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">composition</span><span class="p">)</span><span class="o">.</span><span class="n">total_electrons</span>
        <span class="n">partial_filled</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">orbital</span> <span class="ow">in</span> <span class="n">orbitals</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">electrons</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">break</span>
            <span class="k">if</span> <span class="s1">&#39;s&#39;</span> <span class="ow">in</span> <span class="n">orbital</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
                <span class="n">electrons</span> <span class="o">+=</span> <span class="o">-</span><span class="mi">2</span>
            <span class="k">elif</span> <span class="s1">&#39;p&#39;</span> <span class="ow">in</span> <span class="n">orbital</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
                <span class="n">electrons</span> <span class="o">+=</span> <span class="o">-</span><span class="mi">6</span>
            <span class="k">elif</span> <span class="s1">&#39;d&#39;</span> <span class="ow">in</span> <span class="n">orbital</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
                <span class="n">electrons</span> <span class="o">+=</span> <span class="o">-</span><span class="mi">10</span>
            <span class="k">elif</span> <span class="s1">&#39;f&#39;</span> <span class="ow">in</span> <span class="n">orbital</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
                <span class="n">electrons</span> <span class="o">+=</span> <span class="o">-</span><span class="mi">14</span>
            <span class="n">partial_filled</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">orbital</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">electrons</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">homo</span> <span class="o">=</span> <span class="n">partial_filled</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">lumo</span> <span class="o">=</span> <span class="n">partial_filled</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">homo</span> <span class="o">=</span> <span class="n">partial_filled</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">lumo</span> <span class="o">=</span> <span class="n">orbitals</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="n">partial_filled</span><span class="p">)]</span>
            <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
                <span class="n">lumo</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">return</span> <span class="p">{</span><span class="s1">&#39;HOMO&#39;</span><span class="p">:</span> <span class="n">homo</span><span class="p">,</span> <span class="s1">&#39;LUMO&#39;</span><span class="p">:</span> <span class="n">lumo</span><span class="p">,</span> <span class="s1">&#39;metal&#39;</span><span class="p">:</span> <span class="n">homo</span> <span class="o">==</span> <span class="n">lumo</span><span class="p">}</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.core.molecular_orbitals</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>